package collections1;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Zhuanhuan {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		SimpleDateFormat a = new SimpleDateFormat("yyyy/MM/dd");
		Date date = null;
		System.out.println("请输入一个字符串");
		while (true) {
			String b = input.next();
			a.applyPattern("yyyy-MM-dd");
			try {
				date = a.parse(b);
				System.out.println(a.format(date));
				return;
			} catch (ParseException e) {
				a.applyPattern("yyyyMMdd");
				try {
					date = a.parse(b);
					System.out.println(a.format(date));
					return;
				} catch (ParseException e1) {
					a.applyPattern("yyyy/MM/dd");
					try {
						date = a.parse(b);
						System.out.println(a.format(date));
						return;
					} catch (ParseException e2) {
						System.out.println("日期格式非法！");
						System.out.println("请重新输入一个字符串");
					}
				}
			}
		}
	}
}
